package com.chinasoft.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Random;

@Component
@Aspect
public class Test1wAdvice {

    @Autowired
    Random random;

    @Around("pt()")
    public Object test1w(ProceedingJoinPoint pjp) throws Throwable{
        long sss = System.currentTimeMillis();
        System.out.println("--------------------------------------------------------");
        Object ret =null;
        Object[] args = pjp.getArgs();
        for (int i = 0; i < 100; i++) {
            args[0] = random.nextInt(50);
            ret = pjp.proceed(args);
            System.out.println(ret);
        }

        long eee = System.currentTimeMillis();
        System.out.println("--------------------------------------------------------");
        System.out.println("time："+(eee-sss)/1000+"s");
        return ret;
    }

    @Pointcut("execution(* com.chinasoft.service.BrandService.getOneBrand(..))")
    private void pt(){

    }
}
